﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;
using System.Xml;
using Common.Logging;
using In.Api.Dto.HisWs;
using In.Api.Helpers;
using InDbContext;
using Newtonsoft.Json;
using In.Api.Dto.Qy;

namespace In.Api.Controllers
{
    public class QyWsController : ApiController
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(QyWsController));

        #region 获取各科室现有住院人数统计信息（当天数量）
        /// <summary>
        /// 获取各科室现有住院人数统计信息（当天）        
        /// </summary>
        [HttpPost]
        [ActionName("GetInpatientDeptNumberInfo")]
        public GetInpatientDeptNumberInfoResponse GetInpatientDeptNumberInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetInpatientDeptNumberInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetInpatientDeptNumberInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetInpatientDeptNumberInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetInpatientDeptNumberInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.InpatientDeptNumbers = new List<GetInpatientDeptNumberInfoResponse.InpatientDeptNumberInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var inpatientDeptNumberInfo = new GetInpatientDeptNumberInfoResponse.InpatientDeptNumberInfo();
                    var date = xNode.SelectSingleNode("Date")?.InnerText ?? "";
                    var deptId = xNode.SelectSingleNode("DeptId")?.InnerText ?? "";
                    var deptName = xNode.SelectSingleNode("DeptName")?.InnerText ?? "";
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastCount = xNode.SelectSingleNode("ContrastCount")?.InnerText ?? "";

                    inpatientDeptNumberInfo.Date = date;
                    inpatientDeptNumberInfo.DeptId = deptId;
                    inpatientDeptNumberInfo.DeptName = deptName;
                    inpatientDeptNumberInfo.Total = total;
                    inpatientDeptNumberInfo.ContrastCount = contrastCount;

                    response.InpatientDeptNumbers.Add(inpatientDeptNumberInfo);
                }

            return response;
        }
        #endregion

        #region 获取指定科室现有住院人数统计信息
        /// <summary>
        /// 获取各科室现有住院人数统计信息（当天）        
        /// </summary>
        [HttpPost]
        [ActionName("GetInpatientDeptNumberInfoByDept")]
        public GetInpatientDeptNumberInfoResponse GetInpatientDeptNumberInfoByDept(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetInpatientDeptNumberInfoByDept(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetInpatientDeptNumberInfoByDept 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetInpatientDeptNumberInfoByDept", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetInpatientDeptNumberInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.InpatientDeptNumbers = new List<GetInpatientDeptNumberInfoResponse.InpatientDeptNumberInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var inpatientDeptNumberInfo = new GetInpatientDeptNumberInfoResponse.InpatientDeptNumberInfo();
                    var date = xNode.SelectSingleNode("Date")?.InnerText ?? "";
                    var deptId = xNode.SelectSingleNode("DeptId")?.InnerText ?? "";
                    var deptName = xNode.SelectSingleNode("DeptName")?.InnerText ?? "";
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastCount = xNode.SelectSingleNode("ContrastCount")?.InnerText ?? "";

                    inpatientDeptNumberInfo.Date = date;
                    inpatientDeptNumberInfo.DeptId = deptId;
                    inpatientDeptNumberInfo.DeptName = deptName;
                    inpatientDeptNumberInfo.Total = total;
                    inpatientDeptNumberInfo.ContrastCount = contrastCount;

                    response.InpatientDeptNumbers.Add(inpatientDeptNumberInfo);
                }

            return response;
        }
        #endregion
        #region 获取各科室现有住院人数统计信息（只能从1号开始查询）
        /// <summary>
        /// 获取各科室现有住院人数统计信息（只能从1号开始查询）        
        /// </summary>
        [HttpPost]
        [ActionName("GetInpatientDeptInNumberInfo")]
        public GetInpatientDeptNumberInfoResponse GetInpatientDeptInNumberInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetInpatientDeptInNumberInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetInpatientDeptInNumberInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetInpatientDeptInNumberInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetInpatientDeptNumberInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.InpatientDeptNumbers = new List<GetInpatientDeptNumberInfoResponse.InpatientDeptNumberInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            //<ResultData><DeptId>0706</DeptId><DeptName>发育儿科</DeptName><Total>15</Total><ContrastCount>4</ContrastCount></ResultData>
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var inpatientDeptNumberInfo = new GetInpatientDeptNumberInfoResponse.InpatientDeptNumberInfo();
                    var deptId = xNode.SelectSingleNode("DeptId")?.InnerText ?? "";
                    var deptName = xNode.SelectSingleNode("DeptName")?.InnerText ?? "";
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastCount = xNode.SelectSingleNode("ContrastCount")?.InnerText ?? "";

                    inpatientDeptNumberInfo.DeptId = deptId;
                    inpatientDeptNumberInfo.DeptName = deptName;
                    inpatientDeptNumberInfo.Total = total;
                    inpatientDeptNumberInfo.ContrastCount = contrastCount;

                    response.InpatientDeptNumbers.Add(inpatientDeptNumberInfo);
                }

            return response;
        }
        #endregion

        #region 获取入院总人数（只能从1号开始查询）
        /// <summary>
        /// 获取入院总人数（只能从1号开始查询）        
        /// </summary>
        [HttpPost]
        [ActionName("GetInpatientTotalNumber")]
        public GetInpatientTotalNumberResponse GetInpatientTotalNumber(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetInpatientTotalNumber(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetInpatientTotalNumber 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetInpatientTotalNumber", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetInpatientTotalNumberResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;

            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastTotal = xNode.SelectSingleNode("ContrastTotal")?.InnerText ?? "";

                    response.Total = total;
                    response.ContrastCount = contrastTotal;
                }

            return response;
        }
        #endregion

        #region 获取住院收入
        /// <summary>
        /// 获取住院收入 
        /// </summary>
        [HttpPost]
        [ActionName("GetInpatientIncome")]
        public GetInpatientIncomeResponse GetInpatientIncome(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetInpatientIncome(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetInpatientTotalNumber 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetInpatientTotalNumber", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetInpatientIncomeResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;

            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastTotal = xNode.SelectSingleNode("ContrastTotal")?.InnerText ?? "";
                    var unit = xNode.SelectSingleNode("Unit")?.InnerText ?? "";

                    response.Total = total;
                    response.ContrastCount = contrastTotal;
                    response.Unit = unit;
                }

            return response;
        }
        #endregion


        #region 获取门诊收入 
        /// <summary>
        /// 获取门诊收入  
        /// </summary>
        [HttpPost]
        [ActionName("GetOutpatientIncome")]
        public GetOutpatientIncomeResponse GetOutpatientIncome(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetOutpatientIncome(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetOutpatientIncome 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetOutpatientIncome", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetOutpatientIncomeResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;

            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastTotal = xNode.SelectSingleNode("ContrastTotal")?.InnerText ?? "";
                    var unit = xNode.SelectSingleNode("Unit")?.InnerText ?? "";

                    response.Total = total;
                    response.ContrastCount = contrastTotal;
                    response.Unit = unit;
                }

            return response;
        }
        #endregion

        #region 获取门诊处方量 
        /// <summary>
        /// 获取门诊处方量  
        /// </summary>
        [HttpPost]
        [ActionName("GetOutpatientPrescriptionNumber")]
        public GetOutpatientPrescriptionNumberResponse GetOutpatientPrescriptionNumber(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetOutpatientPrescriptionNumber(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetOutpatientPrescriptionNumber 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetOutpatientPrescriptionNumber", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetOutpatientPrescriptionNumberResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastTotal = xNode.SelectSingleNode("ContrastTotal")?.InnerText ?? "";
                    var unit = xNode.SelectSingleNode("Unit")?.InnerText ?? "";

                    response.Total = total;
                    response.ContrastCount = contrastTotal;
                    response.Unit = unit;
                }

            return response;
        }
        #endregion

        #region 获取各科室门诊处方量统计信息
        /// <summary>
        /// 获取各科室门诊处方量统计信息        
        /// </summary>
        [HttpPost]
        [ActionName("GetOutpatientDeptPrescriptionNumberInfo")]
        public GetOutpatientDeptPrescriptionNumberInfoResponse GetOutpatientDeptPrescriptionNumberInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetOutpatientDeptPrescriptionNumberInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetOutpatientDeptPrescriptionNumberInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetOutpatientDeptPrescriptionNumberInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetOutpatientDeptPrescriptionNumberInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.OutpatientDeptPrescriptionNumberInfos = new List<GetOutpatientDeptPrescriptionNumberInfoResponse.OutpatientDeptPrescriptionNumberInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var outpatientDeptNumberInfo = new GetOutpatientDeptPrescriptionNumberInfoResponse.OutpatientDeptPrescriptionNumberInfo();
                    var date = xNode.SelectSingleNode("Date")?.InnerText ?? "";
                    var deptId = xNode.SelectSingleNode("DeptId")?.InnerText ?? "";
                    var deptName = xNode.SelectSingleNode("DeptName")?.InnerText ?? "";
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastTotal = xNode.SelectSingleNode("ContrastTotal")?.InnerText ?? "";
                    var unit = xNode.SelectSingleNode("Unit")?.InnerText ?? "";

                    outpatientDeptNumberInfo.Date = date;
                    outpatientDeptNumberInfo.DeptId = deptId;
                    outpatientDeptNumberInfo.DeptName = deptName;
                    outpatientDeptNumberInfo.Total = total;
                    outpatientDeptNumberInfo.ContrastCount = contrastTotal;
                    outpatientDeptNumberInfo.Unit = unit;

                    response.OutpatientDeptPrescriptionNumberInfos.Add(outpatientDeptNumberInfo);
                }

            return response;
        }
        #endregion

        #region 获取指定科室门诊处方量统计信息
        /// <summary>
        /// 获取各科室门诊处方量统计信息        
        /// </summary>
        [HttpPost]
        [ActionName("GetOutpatientDeptPrescriptionNumberInfoByDept")]
        public GetOutpatientDeptPrescriptionNumberInfoResponse GetOutpatientDeptPrescriptionNumberInfoByDept(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetOutpatientDeptPrescriptionNumberInfoByDept(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetOutpatientDeptPrescriptionNumberInfoByDept 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetOutpatientDeptPrescriptionNumberInfoByDept", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetOutpatientDeptPrescriptionNumberInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.OutpatientDeptPrescriptionNumberInfos = new List<GetOutpatientDeptPrescriptionNumberInfoResponse.OutpatientDeptPrescriptionNumberInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var outpatientDeptNumberInfo = new GetOutpatientDeptPrescriptionNumberInfoResponse.OutpatientDeptPrescriptionNumberInfo();
                    var date = xNode.SelectSingleNode("Date")?.InnerText ?? "";
                    var deptId = xNode.SelectSingleNode("DeptId")?.InnerText ?? "";
                    var deptName = xNode.SelectSingleNode("DeptName")?.InnerText ?? "";
                    var total = xNode.SelectSingleNode("Total")?.InnerText ?? "";
                    var contrastTotal = xNode.SelectSingleNode("ContrastTotal")?.InnerText ?? "";
                    var unit = xNode.SelectSingleNode("Unit")?.InnerText ?? "";

                    outpatientDeptNumberInfo.Date = date;
                    outpatientDeptNumberInfo.DeptId = deptId;
                    outpatientDeptNumberInfo.DeptName = deptName;
                    outpatientDeptNumberInfo.Total = total;
                    outpatientDeptNumberInfo.ContrastCount = contrastTotal;
                    outpatientDeptNumberInfo.Unit = unit;

                    response.OutpatientDeptPrescriptionNumberInfos.Add(outpatientDeptNumberInfo);
                }

            return response;
        }
        #endregion
        #region 获取自助终端使用情况信息 
        /// <summary>
        /// 获取自助终端使用情况信息  
        /// </summary>
        [HttpPost]
        [ActionName("GetSelfServiceTerminalInfo")]
        public GetSelfServiceTerminalInfoResponse GetSelfServiceTerminalInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetSelfServiceTerminalInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetSelfServiceTerminalInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetSelfServiceTerminalInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetSelfServiceTerminalInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var total = xNode.SelectSingleNode("RegCount")?.InnerText ?? "";
                    var contrastTotal = xNode.SelectSingleNode("ClinPayCount")?.InnerText ?? "";
                    var unit = xNode.SelectSingleNode("Unit")?.InnerText ?? "";
                    var totalMoney = xNode.SelectSingleNode("TotalMoney")?.InnerText ?? "";

                    response.RegCount = total;
                    response.ClinPayCount = contrastTotal;
                    response.Unit = unit;
                    response.TotalMoney = totalMoney;
                }

            return response;
        }
        #endregion


        #region 获取微信使用情况信息 
        /// <summary>
        /// 获取自助终端使用情况信息  
        /// </summary>
        [HttpPost]
        [ActionName("GetWeixinInfo")]
        public GetWeixinInfoResponse GetWeixinInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetWeixinInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetWeixinInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetWeixinInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetWeixinInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var total = xNode.SelectSingleNode("RegCount")?.InnerText ?? "";
                    var contrastTotal = xNode.SelectSingleNode("ClinPayCount")?.InnerText ?? "";
                    var wardDepositCount = xNode.SelectSingleNode("WardDepositCount")?.InnerText ?? "";
                    var totalMoney = xNode.SelectSingleNode("TotalMoney")?.InnerText ?? "";

                    response.RegCount = total;
                    response.ClinPayCount = contrastTotal;
                    response.WardDepositCount = wardDepositCount;
                    response.TotalMoney = totalMoney;
                }

            return response;
        }
        #endregion

        #region 实时统计门诊各科各上班医生当前候诊人数


        /// <summary>
        /// 实时统计门诊各科各上班医生当前候诊人数  
        /// </summary>
        [HttpPost]
        [ActionName("GetOutPatientWaitingInfo")]
        public GetOutPatientWaitingInfoResponse GetOutPatientWaitingInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetOutPatientWaitingInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetOutPatientWaitingInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetOutPatientWaitingInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetOutPatientWaitingInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.OutPatientWaitingInfoes = new List<GetOutPatientWaitingInfoResponse.OutPatientWaitingInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var deptName = xNode.SelectSingleNode("DeptName")?.InnerText ?? "";
                    var doctName = xNode.SelectSingleNode("DoctName")?.InnerText ?? "";
                    var waitingCount = xNode.SelectSingleNode("WaitingCount")?.InnerText ?? "";


                    GetOutPatientWaitingInfoResponse.OutPatientWaitingInfo info = new GetOutPatientWaitingInfoResponse.
                        OutPatientWaitingInfo()
                    {
                        DeptName = deptName,
                        DoctName = doctName,
                        WaitingCount = waitingCount
                    };
                    response.OutPatientWaitingInfoes.Add(info);
                }

            return response;
        }
        #endregion

        #region 实时统计治疗区当前排队人数


        /// <summary>
        /// 实时统计治疗区当前排队人数  
        /// </summary>
        [HttpPost]
        [ActionName("GetTreatmentWaitingInfo")]
        public GetTreatmentWaitingInfoResponse GetTreatmentWaitingInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetTreatmentWaitingInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetTreatmentWaitingInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetTreatmentWaitingInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetTreatmentWaitingInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.TreatmentWaitingInfoes = new List<GetTreatmentWaitingInfoResponse.TreatmentWaitingInfo>();
           var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var treatName = xNode.SelectSingleNode("TreatName")?.InnerText ?? "";
                    var waitingCount = xNode.SelectSingleNode("WaitingCount")?.InnerText ?? "";


                    GetTreatmentWaitingInfoResponse.TreatmentWaitingInfo info = new GetTreatmentWaitingInfoResponse.
                        TreatmentWaitingInfo()
                    {
                        TreatName = treatName,
                        WaitingCount = waitingCount
                    };
                    response.TreatmentWaitingInfoes.Add(info);
                }

            return response;
        }
        #endregion


        #region 获取各科室门诊处方量统计信息
        /// <summary>
        /// 获取各科室门诊处方量统计信息        
        /// </summary>
        [HttpPost]
        [ActionName("GetBedUsedDetailInfo")]
        public GetBedUsedDetailInfoResponse GetBedUsedDetailInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

//            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
//            hospitalIdNode.InnerText = request.StartDate;
//            root.AppendChild(hospitalIdNode);
//
//            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
//            cardNoNode.InnerText = request.EndDate;
//            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetBedUsedDetailInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetBedUsedDetailInfoResponse 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetBedUsedDetailInfoResponse", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetBedUsedDetailInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.Beds = new List<GetBedUsedDetailInfoResponse.BedInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var bedInfo = new GetBedUsedDetailInfoResponse.BedInfo();
                    var deptId = xNode.SelectSingleNode("DeptId")?.InnerText ?? "";
                    var deptName = xNode.SelectSingleNode("DeptName")?.InnerText ?? "";
                    var usedBed = xNode.SelectSingleNode("UsedBed")?.InnerText ?? "";
                    var totalBed = xNode.SelectSingleNode("TotalBed")?.InnerText ?? "";
                    var percent = xNode.SelectSingleNode("Percent")?.InnerText ?? "";

                    bedInfo.DeptId = deptId;
                    bedInfo.DeptName = deptName;
                    bedInfo.UsedBed = usedBed;
                    bedInfo.TotalBed = totalBed;
                    bedInfo.Percent = percent;

                    response.Beds.Add(bedInfo);
                }

            return response;
        }
        #endregion


        #region 获取医城通终端使用情况信息 
        /// <summary>
        /// 获取医城通终端使用情况信息  
        /// </summary>
        [HttpPost]
        [ActionName("GetYCTTerminalInfo")]
        public GetYCTTerminalInfoResponse GetYCTTerminalInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetYCTTerminalInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetYCTTerminalInfo 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetYCTTerminalInfo", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetYCTTerminalInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var total = xNode.SelectSingleNode("RegCount")?.InnerText ?? "";
                    var clinPayCount = xNode.SelectSingleNode("ClinPayCount")?.InnerText ?? "";
                    var unit = xNode.SelectSingleNode("Unit")?.InnerText ?? "";
                    var totalMoney = xNode.SelectSingleNode("TotalMoney")?.InnerText ?? "";

                    response.RegCount = total;
                    response.ClinPayCount = clinPayCount;
                    response.Unit = unit;
                    response.TotalMoney = totalMoney;
                }

            return response;
        }
        #endregion

        #region 获取支付宝端口使用情况信息 
        /// <summary>
        /// 获取支付宝端口使用情况信息  
        /// </summary>
        [HttpPost]
        [ActionName("GetAlipayTerminalInfo")]
        public GetAlipayTerminalInfoResponse GetAlipayTerminalInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetAlipayTerminalInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetAlipayTerminalInfoResponse 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetAlipayTerminalInfoResponse", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetAlipayTerminalInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var total = xNode.SelectSingleNode("RegCount")?.InnerText ?? "";
                    var clinPayCount = xNode.SelectSingleNode("ClinPayCount")?.InnerText ?? "";
                    var unit = xNode.SelectSingleNode("Unit")?.InnerText ?? "";
                    var totalMoney = xNode.SelectSingleNode("TotalMoney")?.InnerText ?? "";

                    response.RegCount = total;
                    response.ClinPayCount = clinPayCount;
                    response.Unit = unit;
                    response.TotalMoney = totalMoney;
                }

            return response;
        }
        #endregion

        #region 获取指定科室门诊处方量统计信息
        /// <summary>
        /// 获取各科室预约率        
        /// </summary>
        [HttpPost]
        [ActionName("GetBookingPercent")]
        public GetBookingPercentResponse GetBookingPercent(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            XmlNode hospitalIdNode = xmlDoc.CreateElement("StartDate");
            hospitalIdNode.InnerText = request.StartDate;
            root.AppendChild(hospitalIdNode);

            XmlNode cardNoNode = xmlDoc.CreateElement("EndDate");
            cardNoNode.InnerText = request.EndDate;
            root.AppendChild(cardNoNode);

            XmlNode deptIdNode = xmlDoc.CreateElement("DeptId");
            deptIdNode.InnerText = request.DeptId;
            root.AppendChild(deptIdNode);

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXGetBookingPercent(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetBookingPercent 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetBookingPercent", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new GetBookingPercentResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.BookingPercentInfoes = new List<GetBookingPercentResponse.BookingPercentInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var bookingInfo = new GetBookingPercentResponse.BookingPercentInfo();
                    var date = xNode.SelectSingleNode("Date")?.InnerText ?? "";
                    var deptId = xNode.SelectSingleNode("DeptId")?.InnerText ?? "";
                    var deptName = xNode.SelectSingleNode("DeptName")?.InnerText ?? "";
                    var bookingNum = xNode.SelectSingleNode("Booking_Num")?.InnerText ?? "";
                    var wXRegNum = xNode.SelectSingleNode("WX_Reg_Num")?.InnerText ?? "";
                    var regNum = xNode.SelectSingleNode("Reg_Num")?.InnerText ?? "";
                    var percent = xNode.SelectSingleNode("Percent")?.InnerText ?? "";

                    bookingInfo.Date = date;
                    bookingInfo.DeptId = deptId;
                    bookingInfo.DeptName = deptName;
                    bookingInfo.BookingNum = bookingNum;
                    bookingInfo.WxRegNum = wXRegNum;
                    bookingInfo.RegNum = regNum;
                    bookingInfo.Percent = percent;

                    response.BookingPercentInfoes.Add(bookingInfo);
                }

            return response;
        }
        #endregion

        #region 获取获取B超排队情况
        /// <summary>
        /// 获取B超排队情况      
        /// </summary>
        [HttpPost]
        [ActionName("BscanWaitingInfo")]
        public BscanWaitingInfoResponse BscanWaitingInfo(QyRequest request)
        {
            var wsClient = WsClientFactory.GetQyWsSoapClient();

            var xmlDoc = new XmlDocument();
            XmlNode root = xmlDoc.CreateElement("Request");

            xmlDoc.AppendChild(root);
            var requestXml = xmlDoc.InnerXml;
            var responseXml = "";

            try
            {
                responseXml = wsClient.DXBscanWaitingInfo(requestXml);
                wsClient.Close();
            }
            catch (Exception ex)
            {
                wsClient.Abort();
                Logger.ErrorFormat("调用 GetBookingPercent 失败，信息：{0}", JsonConvert.SerializeObject(ex));
                throw;
            }

            HospWsLogHelper.Log("GetBookingPercent", requestXml, responseXml);

            xmlDoc = new XmlDocument();
            xmlDoc.LoadXml(responseXml);

            var response = new BscanWaitingInfoResponse();

            var node = xmlDoc.SelectSingleNode("/Response/ResultCode");
            var resultCode = node == null ? "" : node.InnerText;

            node = xmlDoc.SelectSingleNode("/Response/ErrorMsg");
            var resultDesc = node == null ? "" : node.InnerText;

            if (resultCode != "0")
            {
                response.ResultCode = resultCode;
                response.ResultDesc = resultDesc;
                return response;
            }

            response.ResultCode = resultCode;
            response.ResultDesc = resultDesc;
            response.BscanWaitingInfoes = new List<BscanWaitingInfoResponse.BscanWaitingInfo>();
            var nodes = xmlDoc.SelectNodes("/Response/ResultData");
            if (nodes != null)
                foreach (XmlNode xNode in nodes)
                {
                    var bscanWaitingInfo = new BscanWaitingInfoResponse.BscanWaitingInfo();
                    var queueName = xNode.SelectSingleNode("QueueName")?.InnerText ?? "";
                    var waitingCount = xNode.SelectSingleNode("WaitingCount")?.InnerText ?? "";

                    bscanWaitingInfo.QueueName = queueName;
                    bscanWaitingInfo.WaitingCount = waitingCount;

                    response.BscanWaitingInfoes.Add(bscanWaitingInfo);
                }

            return response;
        }
        #endregion

    }
}